const koa = require('koa')
const cors = require('koa-cors')
const app = new koa()


const main = ctx => {
  if (ctx.request.accepts('xml')) {
    ctx.response.type = 'xml'
    ctx.response.body = '<data>Hell</data>'
  } else if (ctx.request.accepts('html')) {
    ctx.response.type = 'html'
    ctx.response.body = '<h1>Hell</h1>'
  } else if (ctx.request.accepts('json')) {
    ctx.response.type = 'json'
    ctx.response.body = '{data: Hello}'
  } else {
    ctx.response.type = 'text'
    ctx.response.body = 'Hello'
  }
}

app.use(cors())
app.use(main)

app.listen(3000)
